home *** CD-ROM | disk | FTP | other *** search
/ ftp.cs.arizona.edu / ftp.cs.arizona.edu.tar / ftp.cs.arizona.edu / icon / newsgrp / group94a.txt / 000079_icon-group-sender _Tue Apr 5 08:26:42 1994.msg < prev    next >
Internet Message Format  |  1994-08-19  |  1KB

  1. Received: by cheltenham.cs.arizona.edu; Tue, 5 Apr 1994 09:01:47 MST
  2. Date: Tue, 5 Apr 1994 08:26:42 +0700
  3. From: swampler@noao.edu
  4. Message-Id: <9404051526.AA04963@orpheus.tuc.noao.edu>
  5. Subject: Re: 2d arrays in Icon
  6. To: icon-group@cs.arizona.edu
  7. Content-Length: 690
  8. Status: R
  9. Errors-To: icon-group-errors@cs.arizona.edu
  10.  
  11.  
  12. In addition to Chris' approach using a table (which is also *very* nice for
  13. sparse arrays), it's pretty easy to write a 2d array 'constructor' function:
  14.  
  15.    procedure array2d(num_rows, num_cols)
  16.       local a
  17.  
  18.       a := list(num_rows)
  19.       every !a := list(num_cols)
  20.  
  21.       return a
  22.    end
  23.  
  24. You can then reference the result, as in:
  25.  
  26.    board := array2d(8, 8)
  27.    board[1][1] := "Q"
  28.  
  29. One nice thing about 2d-arrays in Icon is that they are, indeed, dynamic
  30. (since they are just constructed from lists) - it's not hard to write functions
  31. to grow/shrink them, insert/remove columns/rows, etc. (columns are harder than
  32. rows...)
  33. --
  34. Steve Wampler
  35. swampler@noao.edu
  36. Gemini Project (under AURA)
  37.